﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.IO.IsolatedStorage;

namespace BiHCurrencyConverter.Model
{
    public class ViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<Currency> Currencies {get; set;}
        static IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
        
        
        public ViewModel()
        {
            Currencies = new ObservableCollection<Currency>();
        
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public void InitializeCurrencyCollection()
        {
            Currencies.Clear();
            foreach (var item in settings)
            {
                Currencies.Add(new Currency
                {
                    Symbol = item.Key.ToString(),
                    Rate = Convert.ToDouble(item.Value),
                    ImageUrl = "/images/flags/" + item.Key.ToString() + ".png"
                });
            }
        }
    }
}
